package com.zhr.tea.view.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhr.tea.R;
import com.zhr.tea.entity.shouye.chayi.Chayi;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ChayiEnterActivity extends AppCompatActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_share)
    ImageView ivShare;
    @BindView(R.id.web_newscontent)
    WebView webNewscontent;
    private Chayi.TeaDoctorListBean data = new Chayi.TeaDoctorListBean();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chayi_enter);
        ButterKnife.bind(this);
        data = (Chayi.TeaDoctorListBean) getIntent().getSerializableExtra("cha");
        initView();
    }

    private void initView() {
        tvTitle.setText(data.getArticleTitle());
        setWebView();
        webNewscontent.loadUrl(data.getArticleUrl());
    }


    private void setWebView() {
        WebSettings ws = webNewscontent.getSettings();
        ws.setJavaScriptEnabled(true);  //支持js
        ws.setPluginState(WebSettings.PluginState.ON);//设置是否支持插件
        ws.setUseWideViewPort(false);  //将图片调整到适合webview的大小
        ws.setSupportZoom(true);  //支持缩放
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持内容重新布局
        ws.supportMultipleWindows();  //多窗口
        ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);  //关闭webview中缓存
        ws.setAllowFileAccess(true);  //设置可以访问文件
        ws.setNeedInitialFocus(true); //当webview调用requestFocus时为webview设置节点
        ws.setBuiltInZoomControls(true); //设置支持缩放
        ws.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
        ws.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
        ws.setLoadsImagesAutomatically(true);  //支持自动加载图片
    }

    @OnClick({R.id.iv_back, R.id.iv_share})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_share:
                break;
        }
    }
}
